package edu.bw.service.impl;

import edu.bw.dao.UserDao;
import edu.bw.dao.impl02.UserDaoImpl;
import edu.bw.service.UserService;
import jakarta.annotation.Resource;
import lombok.Data;
import org.springframework.stereotype.Service;

@Service
@Data
public class UserServiceImpl04 implements UserService {
    /**
     * 没有指定name和type属性
     * 1.接口只有一个实现类: 先按照bean的id="userDao"查找 => 没找到 => 按照类型查找(UserDao接口实现类)=> 找到一个 => 注入edu.bw.dao.impl.UserDaoImpl
     * 2.接口有多个实现类:先按照bean的id="userDao"查找 => 没找到 => 按照类型查找(UserDao接口实现类)=> 找到两个 =>抛异常
     * org.springframework.beans.factory.NoUniqueBeanDefinitionException:
     * No qualifying bean of type 'edu.bw.dao.UserDao' available:
     * expected single matching bean but found 2: userDaoImpl02,userDaoImpl
     */
    //@Resource
    //private UserDao userDao;


    //只指定name属性
    //1.接口只有一个实现类: 按照bean的id="userDaoImpl"去查找=>唯一匹配=>注入edu.bw.dao.impl.UserDaoImpl
    //2.接口有多个实现类: 按照bean的id="userDaoImpl"去查找=>唯一匹配=>注入edu.bw.dao.impl.UserDaoImpl
    //@Resource(name = "userDaoImpl")
    //private UserDao userDao;

    //只指定type属性
    //1.接口只有一个实现类: type = UserDaoImpl.class => 按照类型(edu.bw.dao.impl.UserDaoImpl)查找=> 唯一匹配=>直接注入
    //2.接口有多个实现类: type = UserDaoImpl.class => 按照类型(edu.bw.dao.impl.UserDaoImpl)查找=> 唯一匹配=>直接注入
    //                 type = UserDao.class => 按照UserDao的实现查找=> 多个匹配 =>抛异常
    //                  org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'edu.bw.dao.UserDao'
    //                  available: expected single matching bean but found 2: userDaoImpl02,userDaoImpl
    //@Resource(type = UserDao.class)
    //@Resource(type = UserDaoImpl.class)
    //private UserDao userDao;


    //同时指定name和type属性
    //1.接口只有一个实现类: 会按照Bean的id="userDaoImpl" 并且 类型(edu.bw.dao.impl.UserDaoImpl) 匹配唯一bean=> 匹配=> 注入成功
    //2. 接口有多个实现类: 会按照Bean的id="userDaoImpl02" 并且 类型(edu.bw.dao.impl02.UserDaoImpl) 匹配唯一bean=> 匹配=> 注入成功
    //根据需要切换不同的实现类
    //@Resource(name = "userDaoImpl", type = UserDaoImpl.class)
    @Resource(name = "userDaoImpl02", type = UserDaoImpl.class)
    private UserDao userDao;

}
